#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
const int N = 2e3 + 10;
typedef pair<int, int> pii;
vector<pii> edges[N];
int dist[N];
bool bf(int n)
{
    for (int i = 0; i <= n; i++)
    {
        dist[i] = 0x3f3f3f3f;
    }
    dist[1] = 0;
    bool flag;
    for (int i = 1; i <= n; i++)
    {
        flag = false;
        for (int j = 1; j <= n; j++)
        {
            if (dist[j] == 0x3f3f3f3f)
            {
                continue;
            }
            for (auto& e : edges[j])
            {
                int v = e.first;
                int w = e.second;
                if (dist[j] + w < dist[v])
                {
                    dist[v] = dist[j] + w;
                    flag = true;
                }
            }
        }
        if (flag == false)
        {
            return false;
        }
    }
    return true;

}
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        memset(edges, 0, sizeof(edges));
        memset(dist, 0, sizeof(dist));
        int n, m;
        cin >> n >> m;
        for (int i = 1; i <= m; i++)
        {
            int u, v, w;
            cin >> u >> v >> w;
            if (w >= 0)
            {
                edges[u].push_back({ v,w });
                edges[v].push_back({ u,w });
            }
            else
            {
                edges[u].push_back({ v,w });
            }
        }
        bool ret = bf(n);
        if (ret == false)
        {
            cout << "NO" << endl;
        }
        else
        {
            cout << "YES" << endl;
        }
    }
    return 0;
}